<template>
  <div class="box">
    <div class="header">
      <div><router-link to="/">首页</router-link></div>
    </div>
    <div class="content">
      <div>
        <div>登录</div>
        <div>
          <span>手机号：</span>
          <input type="text" v-model="uphone" />
        </div>
        <div>
          <span>密码：</span>
          <input type="password" v-model="upwd" />
        </div>
        <div>
          <span @click="login">登录</span>
        </div>
        <div><router-link to="/reg">还没有账号？去注册&gt;</router-link></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      uphone: "",
      upwd: "",
    };
  },
  methods: {
    login() {
      let { uphone, upwd } = this;
      if (uphone && upwd) {
        const url = "http://1.14.30.101:8888/login";
        let params = `uphone=${uphone}&&upwd=${upwd}`;
        this.axios.post(url, params).then((res) => {
          if (res.data.code == 202) {
            this.$alert(
              "登录失败,该账号已冻结！若有疑问,请联系管理员",
              "登录提示",
              {
                confirmButtonText: "确定",
              }
            );
          } else if (res.data.code == 200) {
            this.$alert("登录成功", "登录提示", {
              confirmButtonText: "确定",
            });
            this.$store.commit("updateUid", res.data.result.uid);
            this.$store.commit("updateUnickname", res.data.result.unickname);
            this.$store.commit("updateUemail", res.data.result.uemail);
            this.$store.commit("updateUlogo", res.data.result.ulogo);
            setTimeout(() => {
              this.$router.push("/");
            }, 2000);
          } else {
            this.$alert("登录失败，手机号或密码错误", "登录提示", {
              confirmButtonText: "确定",
            });
          }
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.header {
  background-color: #90080e;
  height: 40px;
  > div:first-child {
    line-height: 40px;
    margin-left: 10px;
    cursor: pointer;
    > a {
      font-size: 16px;
      color: #fff;
    }
  }
}
.content {
  background: url("../assets/img/f1/bg2.png") no-repeat;
  height: 100%;
  width: 100%;
  background-size: cover;
  background-attachment: fixed;
  min-height: 98vh;
  display: flex;
  align-items: center;
  justify-content: center;
  > div {
    width: 700px;
    height: 300px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    display: flex;
    align-items: center;
    flex-direction: column;
    padding-top: 80px;
    > div:first-child {
      font-size: 36px;
      color: #90080e;
      font-weight: bold;
      margin-bottom: 10px;
      margin-left: 40px;
    }
    > div:nth-child(2) {
      margin-bottom: 20px;
      > span {
        display: inline-block;
        width: 80px;
        font-size: 18px;
        color: black;
      }
      > input {
        width: 350px;
        height: 35px;
        border: 1px solid #aaa;
      }
    }
    > div:nth-child(3) {
      > span {
        display: inline-block;
        width: 80px;
        font-size: 18px;
        color: black;
      }
      > input {
        width: 350px;
        height: 35px;
        border: 1px solid #aaa;
      }
    }
    > div:nth-child(4) {
      > span {
        display: inline-block;
        width: 120px;
        height: 50px;
        color: white;
        background-color: #90080e;
        line-height: 50px;
        text-align: center;
        font-size: 18px;
        border-radius: 30px;
        margin-left: 40px;
        margin-top: 25px;
        cursor: pointer;
        user-select: none;
      }
    }
    > div:last-child {
      margin-top: 20px;
      margin-left: 40px;
      > a {
        color: black;
      }
      > a:hover {
        color: #90080e;
      }
    }
  }
}
</style>
